﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Threading;

namespace 语音播报
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnRead_Click(object sender, EventArgs e)
        {
            string s = txtMes.Text.Trim();
            Thread th = new Thread(Read1);
            //设置为后台线程
            th.IsBackground = true;
            //启动线程
            th.Start(s);

        }
        private void Read1(object s)
        {
            Type type = Type.GetTypeFromProgID("SAPI.SpVoice");
            dynamic spVoice = Activator.CreateInstance(type);
            spVoice.Speak(s.ToString());
        }
        private void Read2(object s)
        {
            SpeechSynthesizer speech = new SpeechSynthesizer();
             
            speech.Rate = 0;
            speech.Volume = 100;
            speech.SpeakAsync(s.ToString());
        }
    }
}
